<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>demo</title>
    <link rel="stylesheet" href="../../static/layui/css/layui.css">
</head>
<body>
<div class="layui-container" style="width: 100%">
    <div class="layui-row"></div>
    <div class="layui-row">
        <form class="layui-form" id="form1" lay-filter="form1">
            <div class="layui-form-item">
                <select class="layui-select" id="subject" name="subject" required lay-verify="required"></select>
            </div>
            <div class="layui-form-item">
                <input type="text" class="layui-input" id="name" name="name" placeholder="姓名" required
                       lay-verify="required" autocomplete="off">
            </div>
            <div class="layui-form-item">
                <input type="text" class="layui-input" id="account" name="account" placeholder="账号" required
                       lay-verify="required" autocomplete="off">
            </div>
            <div class="layui-form-item">
                <input type="password" class="layui-input" id="password" name="password" placeholder="密码" required
                       lay-verify="required" autocomplete="off">
            </div>
            <div class="layui-form-item">
                <input type="password" class="layui-input" id="pwd" name="pwd" placeholder="确认密码" required
                       lay-verify="required" autocomplete="off">
            </div>
            <div class="layui-form-item">
                <button id="register" class="layui-btn" type="submit">注册</button>
            </div>
        </form>
    </div>
    <div class="layui-row"></div>
</div>
</body>
<script type="text/javascript" src="../../static/layui/layui.all.js"></script>
<script type="text/javascript" src="../../static/config.js"></script>
<script type="text/javascript">
    const $ = layui.$;
    const layer = layui.layer;
    const form = layui.form;

    $.post({
        url: baseUrl + "/hospital-web/process/getAllSubject",
        async: false,
        success: function (res) {
            if (res.data != null) {
                for (const obj of res.data) {
                    $("#subject").append(new Option(obj.subjectName, obj.subjectId));
                }
                form.render('select');
            }
        }
    });

    form.on('submit(form1)', function (data) {
        const form1 = form.val('form1');
        console.log(form1);
        if (form1.password !== form1.pwd) {
            layer.msg("两次输入的密码不一致！");
            $("#password").val("");
            $("#pwd").val("");
            return false;
        }
        $.post({
            url: baseUrl + "/hospital-doctor/doctor/register",
            dataType: "json",
            data: form1,
            success: function (res) {
                parent.layer.msg(res.msg);
                if (res.data) {
                    //关闭
                    const index = parent.layer.getFrameIndex(window.name);
                    parent.layer.close(index);
                }
            }
        });
        return false;
    });

</script>
</html>